home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / telecomm / bbs / wwbbs.lha / WWBBS / Programming / Lib / wwbbs_lib.c
C/C++ Source or Header  |  1994-09-23  |  5KB  |  248 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <libraries/wwbbs.h>
  4. #include <ctype.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <proto/wwbbs.h>
  12.  
  13. BOOL Ask(BYTE *prompt,BOOL def)
  14.     {
  15.         BOOL ret=FALSE,kg=TRUE;
  16.         if(prompt)
  17.             printf("~p\n%s (%s,%s)? ",prompt,(def) ? "[Y]" : "Y",(def) ? "N" : "[N]");
  18.         {
  19.             int c;
  20.             while(kg)
  21.                 {
  22.                     c=getchar();
  23.                     if(c==EOF)
  24.                         break;
  25.                     switch(c)
  26.                         {
  27.                             case '\r':
  28.                                 ret=def;
  29.                                 kg=FALSE;
  30.                                 break;
  31.                             case 'Y':
  32.                             case 'y':
  33.                                 ret=TRUE;
  34.                                 kg=FALSE;
  35.                                 break;
  36.                             case 'N':
  37.                             case 'n':
  38.                                 ret=FALSE;
  39.                                 kg=FALSE;
  40.                                 break;
  41.                         }
  42.                 }
  43.         }
  44.         if(!kg)
  45.             {
  46.                 if(ret)
  47.                     printf("~iYes\n");
  48.                 else
  49.                     printf("~iNo\n");
  50.             }
  51.         return(ret);
  52.     }
  53.  
  54. BOOL GetLine(BYTE *id,BYTE *buff,UWORD length,ULONG flags)
  55.     {
  56.         BOOL ret=FALSE;
  57.         UWORD index=0;
  58.         printf("~i");
  59.         if(flags & GLFLG_Edit)
  60.             {
  61.                 index=strlen(buff);
  62.                 buff[index]=NULL;
  63.                 printf(buff);
  64.             }
  65.         else
  66.             strcpy(buff,"");
  67.         {
  68.             BOOL kg=TRUE;
  69.             int c;
  70.             while(kg)
  71.                 {
  72.                     c=getchar();
  73.                     if(c==EOF)
  74.                         break;
  75.                     switch(c)
  76.                         {
  77.                             case '\b':
  78.                                 if(index)
  79.                                     {
  80.                                         index--;
  81.                                         buff[index]=NULL;
  82.                                         printf("\b \b");
  83.                                     }
  84.                                 break;
  85.                             case '\r':
  86.                                 if( !( !index && (flags & GLFLG_NoEmpty) ) )
  87.                                     {
  88.                                         printf("\n");
  89.                                         if(index)
  90.                                             ret=TRUE;
  91.                                         kg=FALSE;
  92.                                     }
  93.                                 break;
  94.                             default:
  95.                                 if(isprint(c) && index<length)
  96.                                     {
  97.                                         if(flags & GLFLG_Format)
  98.                                             {
  99.                                                 if(isalpha(c))
  100.                                                     {
  101.                                                         if( (index && !isalpha(buff[index-1])) || !index)
  102.                                                             c=toupper(c);
  103.                                                         else
  104.                                                             c=tolower(c);
  105.                                                     }
  106.                                             }
  107.                                         if(flags & GLFLG_ToLower)
  108.                                             {
  109.                                                 if(isalpha(c))
  110.                                                     c=tolower(c);
  111.                                             }
  112.                                         if(flags & GLFLG_ToUpper)
  113.                                             {
  114.                                                 if(isalpha(c))
  115.                                                     c=toupper(c);
  116.                                             }
  117.                                         if(flags & GLFLG_Chars)
  118.                                             {
  119.                                                 if(!isalpha(c))
  120.                                                     c=NULL;
  121.                                             }
  122.                                         if(flags & GLFLG_Digits)
  123.                                             {
  124.                                                 if(!isdigit(c))
  125.                                                     c=NULL;
  126.                                             }
  127.                                         if(flags & GLFLG_NoChars)
  128.                                             {
  129.                                                 if(isalpha(c))
  130.                                                     c=NULL;
  131.                                             }
  132.                                         if(flags & GLFLG_NoDigits)
  133.                                             {
  134.                                                 if(isdigit(c))
  135.                                                     c=NULL;
  136.                                             }
  137.                                         if(flags & GLFLG_NoSpaces)
  138.                                             {
  139.                                                 if(isspace(c))
  140.                                                     c=NULL;
  141.                                             }
  142.                                         if(flags & GLFLG_NoPunct)
  143.                                             {
  144.                                                 if(ispunct(c))
  145.                                                     c=NULL;
  146.                                             }
  147.                                         if(flags & GLFLG_BeginChar)
  148.                                             {
  149.                                                 if(!index && !isalpha(c))
  150.                                                     c=NULL;
  151.                                             }
  152.                                         if(flags & GLFLG_BeginDigit)
  153.                                             {
  154.                                                 if(!index && !isdigit(c))
  155.                                                     c=NULL;
  156.                                             }
  157.                                         if(c)
  158.                                             {
  159.                                                 sprintf(&buff[strlen(buff)],"%c",c);
  160.                                                 index++;
  161.                                                 if(flags & GLFLG_NoEcho)
  162.                                                     printf(".");
  163.                                                 else
  164.                                                     printf("%c",c);
  165.                                             }
  166.                                     }
  167.                                 break;
  168.                         }
  169.                     {
  170.                         BOOL pagereceived=FALSE;
  171.                         GetStatusTags(STTAG_Name,id,STTAG_PageReceived,&pagereceived,TAG_END);
  172.                         if(pagereceived)
  173.                             {
  174.                                 printf("~i%s",buff);
  175.                                 SetStatusTags(STTAG_Name,id,STTAG_PageReceived,FALSE,TAG_END);
  176.                             }
  177.                     }
  178.                 }
  179.         }
  180.         return(ret);
  181.     }
  182.  
  183. void ShowText(BYTE *file)
  184.     {
  185.         BYTE rows[4];
  186.         strcpy(rows,"");
  187.         if(GetVar("ROWS",rows,3,NULL)!=-1)
  188.             {
  189.                 FILE *fp;
  190.                 int count=0;
  191.                 printf("~o");
  192.                 if(fp=fopen(file,"r"))
  193.                     {
  194.                         BYTE buff[256];
  195.                         while(fgets(buff,255,fp))
  196.                             {
  197.                                 if(WaitForChar(Input(),0))
  198.                                     {
  199.                                         getchar();
  200.                                         break;
  201.                                     }
  202.                                 if(count==atoi(rows)-1)
  203.                                     {
  204.                                         printf("~pMore ([Y],N)? ");
  205.                                         if(!Ask(NULL,TRUE))
  206.                                             break;
  207.                                     }
  208.                                 printf(buff);
  209.                                 count++;
  210.                             }
  211.                         fclose(fp);
  212.                     }
  213.             }
  214.     }
  215.  
  216. BOOL RunEditor(BYTE *filename)
  217.     {
  218.         BOOL ret=FALSE;
  219.         BYTE editor[256];
  220.         strcpy(editor,"");
  221.         if(GetVar("EDITOR",editor,255,NULL)!=-1)
  222.             {
  223.                 if(strlen(editor))
  224.                     {
  225.                         BYTE cmd[256];
  226.                         sprintf(cmd,"%s \"%s\"",editor,filename);
  227.                         printf("~r");
  228.                         SetMode(Input(),0);
  229.                         SystemTags(cmd,TAG_END);
  230.                         SetMode(Input(),1);
  231.                         {
  232.                             FILE *fp;
  233.                             if(fp=fopen(filename,"r"))
  234.                                 {
  235.                                     fclose(fp);
  236.                                     if(Ask("Save message",TRUE))
  237.                                         ret=TRUE;
  238.                                     else
  239.                                         DeleteFile(filename);
  240.                                 }
  241.                         }
  242.                     }
  243.                 else
  244.                     printf("~s\nPlease select an editor first.\n");
  245.             }
  246.         return(ret);
  247.     }
  248.